//
//  commetsTableViewController.swift
//  todoApp
//
//  Created by lili on 15/2/9.
//  Copyright (c) 2015年 ll studio. All rights reserved.
//

import UIKit

class CommetsTableViewController: UITableViewController {
    var tagArray:NSMutableArray=NSMutableArray();
    
    override func viewWillAppear(animated: Bool) {
        tagArray = NoteDBManger.shareInstance().queryAllTags()
        self.tableView.reloadData()
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        self.title="标签"
        self.tableView.backgroundColor=BACKGROUND_COLOR
        
        // Uncomment the following line to preserve selection between presentations
        // self.clearsSelectionOnViewWillAppear = false
        
        // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
        // self.navigationItem.rightBarButtonItem = self.editButtonItem()
    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    // MARK: - Table view data source
    
    override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
        // #warning Potentially incomplete method implementation.
        // Return the number of sections.
        return 1
    }
    
    override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        // #warning Incomplete method implementation.
        // Return the number of rows in the section.
        //return toDoItems.count;
        return tagArray.count
        
    }

    override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as! UITableViewCell
        
        cell.backgroundColor=BACKGROUND_COLOR
        let cellText: String = (tagArray[indexPath.row] as? String)!;

        if(cellText.isEmpty){
            cell.textLabel?.text = "空标签";
            cell.textLabel?.textColor = UIColor.lightGrayColor();
        }else{
            cell.textLabel?.text = cellText;
            cell.textLabel?.textColor=TEXT_COLOR;
        }
    
        return cell
    }
    

    
    // MARK: - Navigation
    override func prepareForSegue(segue: UIStoryboardSegue?, sender: AnyObject?) {
        
            if (segue!.identifier=="sameTaggedNotes")  {
                var selectedIndexPath:NSIndexPath=self.tableView.indexPathForSelectedRow!
                var sameTaggedviewcontroller:sameTaggedTableViewController=segue!.destinationViewController as! sameTaggedTableViewController
               sameTaggedviewcontroller.selectedTag=(self.tableView.cellForRowAtIndexPath(selectedIndexPath)?.textLabel?.text!)!
            
        }

    }
    
    
}
